package com.zrar.easyweb.demo.uc.service.impl;

import com.zrar.easyweb.demo.uc.dao.UserDao;
import com.zrar.easyweb.demo.uc.service.UserService;
import com.zrar.easyweb.demo.uc.vo.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户服务
 *
 * @author green
 * @date 2019/11/14
 * @company 安人股份
 * @desc
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    /**
     * 添加事务控制，遇到所有异常进行业务回滚
     *
     * @param userId
     * @param email
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserEmail(String userId, String email) {
        int num = userDao.updateUserEmail(userId, email);
        return num > 0;
    }

    @Override
    public UserDetails getUserById(String userId) {
        UserDetails details = userDao.userQuery(userId);
        return details;
    }


    @Override
    public List<UserDetails> getUserList() {
        return userDao.list();
    }

}
